import {
  Controller,
  Get,
  Post,
  Body,
  UseGuards,
  Param,
  ParseIntPipe,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { WalletService } from './wallet.service';
import { AdjustWalletDto } from './dto/adjust-wallet.dto';
import { UserWallet } from './entities/user-wallet.entity';
import { JwtAuthGuard } from '../../../common/guards/jwt-auth.guard';
import { User } from '../../../common/decorators/user.decorator';
import { User as UserEntity } from '../../users/entities/user.entity';

/**
 * 钱包控制器
 */
@ApiTags('钱包管理')
@Controller('member/wallet')
@UseGuards(JwtAuthGuard)
export class WalletController {
  constructor(private readonly walletService: WalletService) {}

  @ApiOperation({ summary: '获取当前用户钱包信息' })
  @ApiResponse({ status: 200, description: '获取成功', type: UserWallet })
  @Get()
  async getMyWallet(@User() user: UserEntity): Promise<UserWallet> {
    return await this.walletService.getWallet(user.id);
  }

  @ApiOperation({ summary: '根据用户ID获取钱包信息（管理员）' })
  @ApiResponse({ status: 200, description: '获取成功', type: UserWallet })
  @Get('user/:userId')
  async getUserWallet(@Param('userId', ParseIntPipe) userId: number): Promise<UserWallet> {
    return await this.walletService.getWallet(userId);
  }

  @ApiOperation({ summary: '调整用户钱包余额（管理员）' })
  @ApiResponse({ status: 200, description: '调整成功', type: UserWallet })
  @Post('adjust')
  async adjustWallet(@Body() adjustDto: AdjustWalletDto): Promise<UserWallet> {
    return await this.walletService.adjustWallet(adjustDto);
  }
}